package food.controller;

import java.io.IOException;


import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import food.dao.UserDao;
import food.model.User;
@WebServlet("/register")

public class RegisterServlet extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		req.setCharacterEncoding("utf-8");
		String username = req.getParameter("username");
		String password = req.getParameter("pwd");
		String email = req.getParameter("email");
		String gender = req.getParameter("ssex");
		User u = new User();
		u.setUsername(username);
		u.setPassword(password);
		u.setEmail(email);
		u.setGender(gender);
		//把用户插入到数据库中完成注册
		UserDao ud = new UserDao();
		ud.register(u);
		req.getRequestDispatcher("login.jsp").forward(req, resp);
	}
		
}
